// store/index.js
import Vue from 'vue';
// import Vuex from 'vuex';

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    userInfo: null, // 存储用户信息，登录后填充
  },
  mutations: {
    setUserInfo(state, userInfo) {
      state.userInfo = userInfo;
    },
    clearUserInfo(state) {
      state.userInfo = null;
    }
  },
  actions: {
    login({ commit }, userInfo) {
      commit('setUserInfo', userInfo); // 设置用户信息
    },
    logout({ commit }) {
      commit('clearUserInfo'); // 清除用户信息
    }
  },
  getters: {
    isLoggedIn(state) {
      return state.userInfo !== null; // 判断是否登录
    },
    getUserRole(state) {
      return state.userInfo ? state.userInfo.role : null; // 获取用户角色
    },
    getUserPermissions(state) {
      return state.userInfo ? state.userInfo.permissions : []; // 获取用户权限
    }
  }
});
